<?php namespace Admin\Controller;
use Common\Model\GoodsList;
use Common\Model\GoodsAttr;
use Common\Model\TypeAttr;

class GoodsListController extends CommonController{
	private $model;
	public function __auto(){
		$this->model=new GoodsList;
	}
	public function index(){
		$gid=Q('get.gid',0,'intval');
		//    	实现对货品表的添加
		if(IS_POST){
			if($this->model->store()) View::success('添加成功',U('index',array('gid'=>$gid)));
			View::error($this->model->getError());
		}
		//处理表格表头的数据，例如颜色，尺码等
		$goodsAttrModel=new GoodsAttr;
		$data=$goodsAttrModel
				->join('shop_type_attr as ta','taid','=','shop_type_attr_taid')
				->where("shop_goods_gid={$gid} AND class=0")
				//分组是干神马的？？？
				->groupBy('ta.taid')
				->get();
//		p($data);
		//添加货品的时候 下拉菜单所选择的内容（一定是从商品属性表中获得）
		foreach ($data as $k => $v) {
			$data[$k]['value']=$goodsAttrModel
								->where("shop_type_attr_taid={$v['taid']} AND shop_goods_gid={$gid}")
								->get();
		}
//		p($data);
		View::with('data',$data);
		
//		显示已经添加的货品
		$goodsListModel=new GoodsList;
		$listData=$goodsListModel->where("shop_goods_gid={$gid}")->get();
		foreach($listData as $k=>$v){
			$listData[$k]['value']=$goodsAttrModel->where("gtid IN({$v['combine']})")->get();
		}
		
		// p($listData);
		View::with('listData',$listData);
		
	    View::make();
	}

//	实现对货品信息表的删除
	public function del(){
	  $glid=Q('get.glid');
	  $shop_goods_gid=Q('get.shop_goods_gid');
	  $this->model->where("glid={$glid}")->delete();
	  View::success('删除成功',U('index',array('gid'=>$shop_goods_gid)));
	}

}
